<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of link
 *
 * @author sony
 */
class linkCategory {
    var $id;
var $category_name;
var $parent;


    function open(){
        global $db;
        $sql="select * from _link_category where id={$this->id}";
        $row=$db->fetch_row($sql);
        if (!empty($row)){
            extract($row);
            $this->category_name=$category_name;
            $this->parent=$parent;

        }
    }

    function openAll(){
        $sql="select * from _link_category order by id asc";
        $result=$db->query($sql);
        return $db->fetch_array($result);
        
    }

    function insert(){
    global $db;
    $sql="insert into _link_category values (null,'{$this->category_name}',
'{$this->parent}')";
    $db->query($sql);
    return mysql_insert_id();
    }

    function update(){
        global $db;
        $sql="update _link_category set category_name='{$this->category_name}',
parent='{$this->parent} where id=".$this->id;
        $db->query($sql);
    }

    function delete(){
        global $db;
        $sql="delete from _link_category where id=".$this->id;
        $db->query($sql);
    }

}
class linkLinks {
var $id;
var $link_caption;
var $link_category;
var $url_link;
var $target;
var $category_name;

    
    function open(){
        global $db;
        $sql="select a.*,b.category_name from _link_links a,_link_category b 
        where a.link_category=b.id and a.id=".$this->id;
        $row=$db->fetch_row($sql);
        if (!empty($row)){
            extract($row);
            $this->link_caption=$link_caption;
            $this->link_category=$link_category;
            $this->url_link=$url_link;
            $this->target=$target;
            $this->category_name=$category_name;
        }
    }

    function openAll(){
        global $db;
        $sql="select a.*,b.category_name from _link_links a,_link_category b 
        where a.link_category=b.id order by a.id asc";
        $result=$db->query($sql);
        return $db->fetch_array($result);
        
    }

    function insert(){
    global $db;
    $sql="insert into _link_links values (null,'{$this->link_caption}',
    {$this->link_category},'{$this->url_link}','{$this->target}')";
    $db->query($sql);
    return mysql_insert_id();
    }

    function update(){
        global $db;
        $sql="update _link_links set link_caption='{$this->link_caption}',
            link_category='{$this->link_category}',
            url_link='{$this->url_link}',
            target='{$this->target}'
            where id=$this->id";
        $db->query($sql);
    }

    function delete(){
        global $db;
        $sql="delete from _link_links where id=".$this->id;
        $db->query($sql);
    }

}
?>
